package GestorDeErrores;


public class TError {
	private Errores error;
	private int fila;
	private int columna;
	private String lexema;
	
	/**
	 * The constructor for an error.
	 * @param e the type of error from enum class ErroresLexicos
	 * @param fila the row where the error is located 
	 * @param columna the column where the error is located
	 */
	public TError(Errores e, String texto, int fila, int columna) {
		this.error = e;
		this.fila  = fila;
		this.columna = columna;
		this.lexema = texto;
	}
	
	/**
	 * Returns the column number where the error is located
	 * @return the column number
	 */
	public int getColumna() {
		return columna;
	}

	/**
	 * Sets the column number for the error
	 * @param columna the column number
	 */
	public void setColumna(int columna) {
		this.columna = columna;
	}
	
	/**
	 * Returns the row number where the error is located
	 * @return the row number
	 */
	public int getFila() {
		return fila;
	}
	
	/**
	 * Sets the row number for the error
	 * @param fila
	 */
	public void setFila(int fila) {
		this.fila = fila;
	}
	
	/**
	 * Returns the type of error:
	 * <table>
	 * <tr><td>LEXICO_ELEMENTO_YA_INSERTADO<td> Lexer internal error, the element is already inserted in the symbol table
	 * <tr><td>LEXICO_CARACTER_NO_VALIDO<td> Lexer error, the character doesn't generate a valid token
	 * <tr><td>LEXICO_ERROR_DE_IO<td> Lexer error, the file is invalid, couldn't be read...
	 * </table> 
	 * @return the type of error
	 * 
	 */
	public Errores getError() {
		return error;
	}
	
	/**
	 * Sets the type of error:
	 * <table>
	 * <tr><td>LEXICO_ELEMENTO_YA_INSERTADO<td> Lexer internal error, the element is already inserted in the symbol table
	 * <tr><td>LEXICO_CARACTER_NO_VALIDO<td> Lexer error, the character doesn't generate a valid token
	 * <tr><td>LEXICO_ERROR_DE_IO<td> Lexer error, the file is invalid, couldn't be read...
	 * </table> 
	 * @param error the type of error
	 */
	public void setError(Errores error) {
		this.error = error;
	}
	
	//Alberto: método heredado de Object añadido para que todo sea más sencillo
	public String toString(){
		String error = new String();
		error += "Linea: ";
		error += this.fila;
		error += " Columna: ";
		error += this.columna;
		error += ". ";
		// Sustituye los _ por espacios
		error += this.error.toString().replace("_", " ");
		error += " : ";
		error += this.lexema;
		error += " ";
		return error;
	}
}
